

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>agpy.collapseplot &mdash; agpy 0.1 documentation</title>
    
    <link rel="stylesheet" href="../../_static/agogo.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="agpy 0.1 documentation" href="../../index.html" />
    <link rel="up" title="agpy" href="../agpy.html" />
     
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setDomainName', 'pyspeckit.bitbucket.org']);
      _gaq.push(['_setAllowHash', false]);
      _gaq.push(['_trackPageview']);


    </script>
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="../../index.html">agpy 0.1 documentation</a></h1>
        <div class="rel">
          <a href="http://agpy.googlecode.com">agpy Home </a>  |
          <a href=../../index.html>Docs Home </a>  |
          <a href="http://code.google.com/p/agpy/w/list">Wiki</a>  |
          <a href=../../search.html>Search </a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for agpy.collapseplot</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Integrate a cube over some velocities and plot it with aplpy.  Most of this</span>
<span class="sd">functionality is subsumed by :mod:cubes</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">aplpy</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="k">print</span> <span class="s">&quot;aplpy is required for collapseplot&quot;</span>
<span class="kn">import</span> <span class="nn">pyfits</span>
<span class="kn">from</span> <span class="nn">pylab</span> <span class="kn">import</span> <span class="o">*</span>

<div class="viewcode-block" id="collapseplot"><a class="viewcode-back" href="../../agpy.html#agpy.collapseplot.collapseplot">[docs]</a><span class="k">def</span> <span class="nf">collapseplot</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">vrange</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">],</span> <span class="n">outfilename</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">contourfile</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
        <span class="nb">xrange</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">yrange</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">imfile</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">swapcontour</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> 
        <span class="n">hdu</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">vmin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">vmax</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">integrate</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Collapses a data cube over velocities specified by vrange</span>
<span class="sd">    Inputs:</span>
<span class="sd">    filename - name of data cube (.fits)</span>
<span class="sd">    vrange - velocity range (units depend on header)</span>

<span class="sd">    Optional inputs:</span>
<span class="sd">    outfilename - will write collapsed cube to an outfile.</span>
<span class="sd">        clobber - if outfilename set, allows clobbering</span>
<span class="sd">    contourfile - overlays contours from this file.  Accepts **kwargs</span>
<span class="sd">    swapcontour - switch which image will be greyscale and which will be contours</span>
<span class="sd">    imfile - saves file as an image</span>
<span class="sd">    xrange, yrange - crops image to [xmin,xmax] and [ymin,ymax] where x,y</span>
<span class="sd">        are in the header coordinates</span>
<span class="sd">    vmin,vmax - grayscale for plotting</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nb">file</span> <span class="o">=</span> <span class="n">collapsecube</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="n">vrange</span><span class="p">,</span><span class="n">outfilename</span><span class="o">=</span><span class="n">outfilename</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="n">clobber</span><span class="p">,</span><span class="n">integrate</span><span class="o">=</span><span class="n">integrate</span><span class="p">,</span><span class="n">hdu</span><span class="o">=</span><span class="n">hdu</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">xrange</span> <span class="ow">or</span> <span class="n">yrange</span><span class="p">:</span>
        <span class="nb">file</span> <span class="o">=</span> <span class="n">cropfits</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span><span class="nb">xrange</span><span class="o">=</span><span class="nb">xrange</span><span class="p">,</span><span class="n">yrange</span><span class="o">=</span><span class="n">yrange</span><span class="p">)</span>

    
    <span class="k">if</span> <span class="n">contourfile</span><span class="p">:</span>
        <span class="n">cf</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">contourfile</span><span class="p">)</span>
        <span class="n">cf</span> <span class="o">=</span> <span class="n">cropfits</span><span class="p">(</span><span class="n">cf</span><span class="p">,</span><span class="nb">xrange</span><span class="o">=</span><span class="nb">xrange</span><span class="p">,</span><span class="n">yrange</span><span class="o">=</span><span class="n">yrange</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">swapcontour</span><span class="p">:</span>
            <span class="n">fig</span> <span class="o">=</span> <span class="n">aplpy</span><span class="o">.</span><span class="n">FITSFigure</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
            <span class="n">fig</span><span class="o">.</span><span class="n">show_grayscale</span><span class="p">(</span><span class="n">vmin</span><span class="o">=</span><span class="n">vmin</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="n">vmax</span><span class="p">)</span>
            <span class="n">fig</span><span class="o">.</span><span class="n">show_contour</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">fig</span> <span class="o">=</span> <span class="n">aplpy</span><span class="o">.</span><span class="n">FITSFigure</span><span class="p">(</span><span class="nb">file</span><span class="p">)</span>
        <span class="n">fig</span><span class="o">.</span><span class="n">show_grayscale</span><span class="p">(</span><span class="n">vmin</span><span class="o">=</span><span class="n">vmin</span><span class="p">,</span><span class="n">vmax</span><span class="o">=</span><span class="n">vmax</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">contourfile</span><span class="p">:</span> <span class="n">fig</span><span class="o">.</span><span class="n">show_contour</span><span class="p">(</span><span class="n">cf</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">imfile</span><span class="p">:</span>
        <span class="n">fig</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">imfile</span><span class="p">,</span><span class="n">dpi</span><span class="o">=</span><span class="mi">150</span><span class="p">)</span>

    <span class="n">show</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">fig</span>
    
    </div>
<div class="viewcode-block" id="cropfits"><a class="viewcode-back" href="../../agpy.html#agpy.collapseplot.cropfits">[docs]</a><span class="k">def</span> <span class="nf">cropfits</span><span class="p">(</span><span class="n">fitsfile</span><span class="p">,</span><span class="nb">xrange</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">yrange</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">hdu</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Crop a fits file in the range specified by xrange,yrange </span>
<span class="sd">    in header units</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="n">im</span> <span class="o">=</span> <span class="n">fitsfile</span><span class="p">[</span><span class="n">hdu</span><span class="p">]</span><span class="o">.</span><span class="n">data</span>
    <span class="n">header</span> <span class="o">=</span> <span class="n">fitsfile</span><span class="p">[</span><span class="n">hdu</span><span class="p">]</span><span class="o">.</span><span class="n">header</span> 

    <span class="k">try</span><span class="p">:</span>
        <span class="n">dx</span><span class="p">,</span><span class="n">x0</span><span class="p">,</span><span class="n">x0pix</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CD1_1&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL1&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX1&#39;</span><span class="p">]</span>
        <span class="n">dy</span><span class="p">,</span><span class="n">y0</span><span class="p">,</span><span class="n">y0pix</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CD2_2&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL2&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX2&#39;</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span> 
            <span class="n">dx</span><span class="p">,</span><span class="n">x0</span><span class="p">,</span><span class="n">x0pix</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CDELT1&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL1&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX1&#39;</span><span class="p">]</span>
            <span class="n">dy</span><span class="p">,</span><span class="n">y0</span><span class="p">,</span><span class="n">y0pix</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CDELT2&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL2&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX2&#39;</span><span class="p">]</span>
        <span class="k">except</span><span class="p">:</span> 
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;Failed to read header&#39;</span><span class="p">)</span>

    <span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">arange</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">])</span><span class="o">-</span><span class="p">(</span><span class="n">x0pix</span><span class="o">-</span><span class="mf">1.</span><span class="p">))</span><span class="o">*</span><span class="n">dx</span> <span class="o">+</span> <span class="n">x0</span>
    <span class="n">y</span> <span class="o">=</span> <span class="p">(</span><span class="n">arange</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">])</span><span class="o">-</span><span class="p">(</span><span class="n">y0pix</span><span class="o">-</span><span class="mf">1.</span><span class="p">))</span><span class="o">*</span><span class="n">dy</span> <span class="o">+</span> <span class="n">y0</span>

    <span class="k">if</span> <span class="nb">xrange</span><span class="p">:</span>
        <span class="n">xmin</span> <span class="o">=</span> <span class="n">argmin</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="nb">xrange</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
        <span class="n">xmax</span> <span class="o">=</span> <span class="n">argmin</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="nb">xrange</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="n">xmin</span><span class="p">]</span>
        <span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span>
        <span class="n">im</span> <span class="o">=</span> <span class="n">im</span><span class="p">[:,</span><span class="n">xmin</span><span class="p">:</span><span class="n">xmax</span><span class="p">]</span>
    <span class="k">if</span> <span class="n">yrange</span><span class="p">:</span>
        <span class="n">ymin</span> <span class="o">=</span> <span class="n">argmin</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">y</span><span class="o">-</span><span class="n">yrange</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">ymax</span> <span class="o">=</span> <span class="n">argmin</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">y</span><span class="o">-</span><span class="n">yrange</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
        <span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="n">ymin</span><span class="p">]</span>
        <span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span>
        <span class="n">im</span> <span class="o">=</span> <span class="n">im</span><span class="p">[</span><span class="n">ymin</span><span class="p">:</span><span class="n">ymax</span><span class="p">,:]</span>

    <span class="n">fitsfile</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">im</span>
    <span class="n">header</span><span class="p">[</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">im</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">header</span><span class="p">[</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">im</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">fitsfile</span>
</div>
<div class="viewcode-block" id="collapsecube"><a class="viewcode-back" href="../../agpy.html#agpy.collapseplot.collapsecube">[docs]</a><span class="k">def</span> <span class="nf">collapsecube</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="n">vrange</span><span class="p">,</span><span class="n">outfilename</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">integrate</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">hdu</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">    Collapses a datacube over some velocity range and returns the</span>
<span class="sd">    pyfits HDU that includes it.  Optionally writes to disk.</span>
<span class="sd">    filename - input DATA CUBE file name</span>
<span class="sd">    vrange - velocity or frequency range over which to sum</span>

<span class="sd">    Optional inputs:</span>
<span class="sd">    outfilename - file name to write to (default None)</span>
<span class="sd">    clobber - overwrite extant filename (default True)</span>
<span class="sd">    integrate - is output an integral (i.e. sum * delta-V) [default True]</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nb">file</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
    <span class="n">cube</span> <span class="o">=</span> <span class="nb">file</span><span class="p">[</span><span class="n">hdu</span><span class="p">]</span><span class="o">.</span><span class="n">data</span>
    <span class="n">header</span> <span class="o">=</span> <span class="nb">file</span><span class="p">[</span><span class="n">hdu</span><span class="p">]</span><span class="o">.</span><span class="n">header</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">dv</span><span class="p">,</span><span class="n">v0</span><span class="p">,</span><span class="n">v0pix</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CD3_3&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL3&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX3&#39;</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span> 
            <span class="n">dv</span><span class="p">,</span><span class="n">v0</span><span class="p">,</span><span class="n">v0pix</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CDELT3&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL3&#39;</span><span class="p">],</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX3&#39;</span><span class="p">]</span>
            <span class="n">header</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="s">&#39;CD1_1&#39;</span><span class="p">,</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CDELT1&#39;</span><span class="p">])</span>
            <span class="n">header</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="s">&#39;CD2_2&#39;</span><span class="p">,</span><span class="n">header</span><span class="p">[</span><span class="s">&#39;CDELT2&#39;</span><span class="p">])</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;Failed to read 3rd dimension of data cube.&quot;</span><span class="p">)</span>
    <span class="n">vel</span> <span class="o">=</span> <span class="p">(</span><span class="n">arange</span><span class="p">(</span><span class="n">cube</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">-</span><span class="p">(</span><span class="n">v0pix</span><span class="o">-</span><span class="mf">1.</span><span class="p">))</span><span class="o">*</span><span class="n">dv</span> <span class="o">+</span> <span class="n">v0</span>

    <span class="n">im</span> <span class="o">=</span> <span class="n">cube</span><span class="p">[((</span><span class="n">vel</span><span class="o">&gt;</span><span class="n">vrange</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">*</span><span class="p">(</span><span class="n">vel</span><span class="o">&lt;</span><span class="n">vrange</span><span class="p">[</span><span class="mi">1</span><span class="p">])),:,:]</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">integrate</span><span class="p">:</span>
        <span class="n">im</span> <span class="o">*=</span> <span class="n">dv</span>

    <span class="nb">file</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">im</span>

    <span class="n">header</span><span class="p">[</span><span class="s">&#39;NAXIS&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
    <span class="k">del</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CRVAL3&#39;</span><span class="p">]</span>
    <span class="k">del</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CRPIX3&#39;</span><span class="p">]</span>
    <span class="k">del</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;NAXIS3&#39;</span><span class="p">]</span>
    <span class="k">try</span><span class="p">:</span> <span class="k">del</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CDELT3&#39;</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span> <span class="k">pass</span>
    <span class="k">try</span><span class="p">:</span> <span class="k">del</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CD3_3&#39;</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span> <span class="k">pass</span>
    
    <span class="c"># Deal with weird header types</span>
    <span class="k">if</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CTYPE1&#39;</span><span class="p">][</span><span class="o">-</span><span class="mi">3</span><span class="p">:]</span> <span class="o">==</span> <span class="s">&#39;GLS&#39;</span><span class="p">:</span>
        <span class="n">header</span><span class="p">[</span><span class="s">&#39;CTYPE1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CTYPE1&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">3</span><span class="p">]</span><span class="o">+</span><span class="s">&#39;CAR&#39;</span>
    <span class="k">if</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CTYPE2&#39;</span><span class="p">][</span><span class="o">-</span><span class="mi">3</span><span class="p">:]</span> <span class="o">==</span> <span class="s">&#39;GLS&#39;</span><span class="p">:</span>
        <span class="n">header</span><span class="p">[</span><span class="s">&#39;CTYPE2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="s">&#39;CTYPE2&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">3</span><span class="p">]</span><span class="o">+</span><span class="s">&#39;CAR&#39;</span>

    <span class="k">if</span> <span class="n">outfilename</span><span class="p">:</span>
        <span class="nb">file</span><span class="o">.</span><span class="n">writeto</span><span class="p">(</span><span class="n">outfilename</span><span class="p">,</span> <span class="n">clobber</span><span class="o">=</span><span class="n">clobber</span><span class="p">)</span>

    <span class="k">return</span> <span class="nb">file</span>
</pre></div></div>

          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul>
<li class="toctree-l1"><a class="reference internal" href="../../agpy.html">Adam Ginsburg&#8217;s Python Code (agpy)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../image_tools.html">Image Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fft_tools.html">AG_fft_tools Package</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../plfit.html">plfit Package</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="../../search.html" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer">
      &copy; Copyright 2011, Adam Ginsburg.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2pre.
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-6253248-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
        
    </div>
  </body>
</html>